﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Verifications;
using Pixysoft.Weblications.Sango.Entities;

namespace Pixysoft.Weblications.Sango.Environment
{
    class PtyPartymissionHelper
    {
        private static List<Pty_Partymission> orms = new List<Pty_Partymission>();

        public static void initialize()
        {
            orms = SettingHelper.GetNoebe().EntityNoebeCommand.Select<Pty_Partymission>();

            LoggerHelper.Info("initialize Pty_Partymission.count {0}", orms.Count);
        }

        public static Pty_Partymission searchByCode(long code)
        {
            Pty_Partymission orm = trySearchByCode(code);

            if (orm == null)
                throw Exceptions.VerificationFailedException(code);

            return orm;
        }

        public static Pty_Partymission trySearchByCode(long code)
        {
            foreach (Pty_Partymission orm in orms)
            {
                if (orm.Missiontypecode == code)
                    return orm;
            }

            return null;
        }

        public static List<Pty_Partymission> searchAll()
        {
            return orms;
        }

        internal static List<Pty_Partymission> searchOpenMissions(long level)
        {
            List<Pty_Partymission> list = new List<Pty_Partymission>();

            foreach (Pty_Partymission orm in orms)
            {
                if (orm.Visiblelevel == level)
                    list.Add(orm);
            }

            return list;
        }
    }
}
